﻿using GameDataTempshitEditor.Widgets;
using Red.GameData;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GameDataTempshitEditor.DataEditors
{
    /// <summary>
    /// Group of properties sharing the same category
    /// </summary>
    public class GameData_PropertyGroup_Category : Widgets.PropertyGroupBase
    {
        public GameData_PropertyGroup_Category(PropertyItemBase parent, EditorContext context, string name, List<EditorPropertyView> props, bool canEdit)
            : base(parent, name)
        {
            _Context = context;
            _CanEdit = canEdit;
            _Props = props;
            Expand();
        }

        public override bool ExpandElement(ref List<PropertyItemBase> newElements)
        {
            foreach (var prop in _Props)
            {
                if (prop.IsArray)
                    newElements.Add(new GameData_PropertyArray(this, _Context, prop, _CanEdit));
                else
                    newElements.Add(new GameData_PropertyItem(this, _Context, prop, _CanEdit));
            }

            return true;
        }

        private readonly EditorContext _Context;
        private List<EditorPropertyView> _Props;
        private bool _CanEdit;
    }
}
